<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>4.Symbol在缓存容器中的使用</title>
</head>
<body>
  <script>
    class Cache {
      static data = {};
      static set(name,value){
        return  (this.data[name] = value);
      }
      static get(name) {
        return this.data[name];
      }
    }

    //使用Symbol生成key值，不必担心会重复，
    let user = {
      name: "apple",
      desc: "用户资料",
      key: Symbol("资料")
    };
    let cart = {
      name: "apple",
      desc: "购物车",
      key: Symbol("资料")
    };
    Cache.set(user.key,user);
    Cache.set(cart.key,cart);
    console.log(Cache.get(cart.key)); // {name: 'apple', desc: '购物车', key: Symbol(资料)}}

  </script>
  
</body>
</html>